﻿

using Microsoft.AspNetCore.Mvc;
using SmartWMS.API.Controllers;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Server.SystemSets.RoleServices;
using SmartWMS.Server.SystemSets.RoleServices.Dto;

namespace SmartWMS.API.Controllers.SystemSet
{
    /// <summary>
    /// 角色管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "XTong")]
    public class RoleController : TransientController
    {
        private readonly IRoleSerivce _roleService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_roleService"></param>
        public RoleController(IRoleSerivce roleService)
        {
            _roleService = roleService;
        }

        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="role">要添加的数据</param>
        /// <returns>返回状态</returns>
        [HttpPost]
        public async Task<Response<bool>> AddRoleAsyne(RoleDto role)
        {
            try
            {
                var result = await _roleService.AddRoleAsyne(role);
                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 删除角色禁用
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> DelRoleDtoAsyne(RoleDto input)
        {
            try
            {
                var result = await _roleService.DelRoleDtoAsyne(input);
                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <returns>查询列表</returns>
        [HttpPost]
        public async Task<Response<List<RoleDto>>> GetRoleDtoAsyne(string? name)
        {
            try
            {
                var result = await _roleService.GetRoleDtoAsyne(name);
                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }



        /// <summary>
        /// 反填角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<RoleDto> RackRoleDto(int id)
        {
            try
            {
                var result = _roleService.RackRoleDto(id);
                return result;
            }
            catch (Exception)
            {
                throw;
            }

        }
        /// <summary>
        /// 编辑角色列表
        /// </summary>
        /// <param name="input">要编辑的列表</param>
        /// <returns>返回数据</returns>
        [HttpPost]
        public async Task<Response<bool>> UpdRoleAsync(RoleDto input)
        {
            try
            {
                var result = await _roleService.UpdRoleAsync(input);
                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }




        /// <summary>
        /// 添加角色权限
        /// </summary>
        /// <param name="rolePermission"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddRolePermissionAsync(RoleInput rolePermission)
        {
            var result = await _roleService.AddRolePermissionAsync(rolePermission);
            return result;
        }
        /// <summary>
        /// 反填角色权限（树形）
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<int>> SelRolePermissionAsync(RoleInput rolePermission)
        {
            var result = await _roleService.SelRolePermissionAsync(rolePermission);
            return result;
        }

        /// <summary>
        /// 树形菜单
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        [HttpPost]
        public List<PermissionDto> GetRoleMoent(int pid)
        {
            try
            {
                var result = _roleService.GetRoleMoent(pid);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}
